#include<stdlib.h>
#include<allegro.h>
#include"fonction.h"
#include"scene.h"
#include<stdio.h>
int main(){
             int mo=0;    
	
	heros hero;
	guru gur1;

        allegro_init();
	if(install_keyboard() ==-1){
		allegro_message("ERROR! %s",allegro_error);
		return -1;
	}
	set_color_depth(16);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED,1280,800,0,0) !=0){
		set_gfx_mode(GFX_TEXT,0,0,0,0);
		allegro_message("unable to intialize video mode!\n%s\n",allegro_error);
	return 1;}
	
		 install_mouse();
	
	
	
	buffer = create_bitmap(1280,800);
	pau[0]=load_bitmap("../img/jauge/pause00.bmp",NULL);
	pau[1]=load_bitmap("../img/jauge/pause01.bmp",NULL);
	pau[2]=load_bitmap("../img/jauge/pause02.bmp",NULL);
	pau[3]=load_bitmap("../img/jauge/pause03.bmp",NULL);
	MAIN[0]=load_bitmap("../img/menu/main00.bmp",NULL);
	MAIN[1]=load_bitmap("../img/menu/main1.bmp",NULL);
	MAIN[2]=load_bitmap("../img/menu/main2.bmp",NULL);
	MAIN[3]=load_bitmap("../img/menu/main3.bmp",NULL);
	MAIN[4]=load_bitmap("../img/menu/main4.bmp",NULL);
	MAIN[5]=load_bitmap("../img/menu/main5.bmp",NULL);
	cre=load_bitmap("../img/menu/credit.bmp",NULL);
        mat=load_bitmap("../img/menu/mtar9a.bmp",NULL);
	/*set=load_bitmap("../img/menu/settings.bmp",NULL);*/ 
	
	sasirguru(&gur1);

	saisirhero (&hero);

	initialiser(&hero,&gur1);

	 if ( MAIN==NULL){
		allegro_message("could not load images");
	 	allegro_exit();}
	
	 	blit(MAIN[0],buffer,0,0,0,0,SCREEN_W, SCREEN_H);
		blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);


		
		



/*c'est la boucle du jeu*/		

while(!key[KEY_ESC]){mo=0;
set_mouse_cursor_bitmap(MOUSE_CURSOR_ALLEGRO,mat);
show_mouse(buffer);
while(mouse_x>470  && mouse_x<965 && mouse_y>237 && mouse_y<321){
show_mouse(buffer);
	if(mouse_b & 1 ){

	indice=1;
		if (indice==1){ background=load_bitmap("../img/jauge/scene1.bmp",NULL); 
				if(background==NULL){allegro_message("could not load images");
		 				allegro_exit();}
				indice=scene1(indice,&hero,&gur1,background);
				}

		if (indice==2){   
				 background=load_bitmap("../img/jauge/scene2.bmp",NULL);
				if(background==NULL){
						allegro_message("could not load images");
		 				allegro_exit();}
			
				indice=scene2(indice,&hero,&gur1,background);}		
	}



			blit(MAIN[1],buffer,0,0,0,0,SCREEN_W,SCREEN_H);
show_mouse(buffer);
			blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);}
		
while(mouse_x>470  && mouse_x<965 && mouse_y>338 && mouse_y<428){

			blit(MAIN[2],buffer,0,0,0,0,SCREEN_W,SCREEN_H);
show_mouse(buffer);
			blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
if(mouse_b & 1) {
k=fopen("save.txt","r");
fscanf(k,"%d",&indice);
fclose(k);
if (indice==1){ background=load_bitmap("../img/jauge/scene1.bmp",NULL); 
				if(background==NULL){allegro_message("could not load images");
		 				allegro_exit();}
				indice=scene1(indice,&hero,&gur1,background);
				}

		if (indice==2){   
				 background=load_bitmap("../img/jauge/scene2.bmp",NULL);
				if(background==NULL){
						allegro_message("could not load images");
		 				allegro_exit();}
			
				indice=scene2(indice,&hero,&gur1,background);}	
} }
		
while(mouse_x>470  && mouse_x<965 && mouse_y>443 && mouse_y<553){

		blit(MAIN[3],buffer,0,0,0,0,SCREEN_W,SCREEN_H);
                show_mouse(buffer);
		blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
	

}

while(mouse_x>470  && mouse_x<965 && mouse_y>546 && mouse_y<633){

		blit(MAIN[4],buffer,0,0,0,0,SCREEN_W,SCREEN_H);
                show_mouse(buffer);
		blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
	if(mouse_b & 1 ){while(mo==0){
			blit(cre,buffer,0,0,0,0,SCREEN_W,SCREEN_H);
			blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
if(key[KEY_ESC]){mo=1;}
	}

}}
		
while(mouse_x>470  && mouse_x<965 && mouse_y>649 && mouse_y<715 ){
						
		blit(MAIN[5],buffer,0,0,0,0,SCREEN_W,SCREEN_H);
show_mouse(buffer);
		blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
			if(mouse_b & 1 ){
			return 0;
			}
		blit(MAIN[5],buffer,0,0,0,0,SCREEN_W,SCREEN_H);
show_mouse(buffer);
		blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
		}
			blit(MAIN[0],buffer,0,0,0,0,SCREEN_W, SCREEN_H);
show_mouse(buffer);
		blit(buffer, screen, 0,0,0,0,SCREEN_W, SCREEN_H);
		


}
	readkey();
	destroy_bitmap(buffer);
	return 0;




}







